{{template "admin/top.html" .}}
<div class="m-b-md"> <h3 class="m-b-none">Users</h3></div>

<section class="panel panel-default">
	<div class="row wrapper">
		<div class="col-sm-5 m-b-xs">
			<button class="btn btn-sm btn-default bulk-email">
				Send Email
			</button>
		</div>
		<div class="col-sm-4 m-b-xs">
			
		</div>
		<div class="col-sm-3">
			<div class="input-group search-group">
				<input type="text" class="input-sm form-control" placeholder="Username or Email" id="keywords" value="{{.keywords}}" />
				<span class="input-group-btn">
					<button class="btn btn-sm btn-default" type="button" data-url="/adminUser/index">Search</button>
				</span>
			</div>
		</div>
	</div>
	<div class="table-responsive">
		<table class="table table-striped b-t b-light">
			<thead>
				<tr>
					<th width="20">
						<input type="checkbox">
					</th>
					{{$url := urlConcat "/adminUser/index" "keywords" .keywords}}
					<th 
					{{sorterTh $url "email" .sorter}}
					>
						Email
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th
					{{sorterTh $url "username" .sorter}}
					>
						Username
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th
					{{sorterTh $url "verified" .sorter}}
					>
						Verified
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th
					{{sorterTh $url "createdTime" .sorter}}
					>
						Register Date
						<span class="th-sort">
							<i class="fa fa-sort-down"></i>
							<i class="fa fa-sort-up"></i>
							<i class="fa fa-sort"></i>
						</span>
					</th>
					<th width="30">
					</th>
				</tr>
			</thead>
			<tbody>
				{{range .users}}
				<tr>
					<td>
						<input type="checkbox" class="ck" data-email="{{.Email}}" data-id="{{.UserId.Hex}}">
					</td>
					<td>
						<a target="_blank" href="/blog/{{.UserId.Hex}}">{{.Email}}</a>
					</td>
					<td>
						{{.Username}}
					</td>
					<td>
						{{.Verified}}
					</td>
					<td>
						{{.CreatedTime|datetime}}
					</td>
					<td>
						<a href="#" class="btn btn-sm btn-default reset-pwd" data-id="{{.UserId.Hex}}">Reset Password</a>
						<a href="#" class="btn btn-sm btn-default send-email" data-email="{{.Email}}">Send Email</a>
					</td>
				</tr>
				{{end}}
			</tbody>
		</table>
	</div>
	<footer class="panel-footer">
		<div class="row">
			<div class="col-sm-4 hidden-xs">
				<button class="btn btn-sm btn-default bulk-email">
					Send Email
				</button>
			</div>
			
			<div class="col-sm-8 text-right text-center-xs">
				{{set . "url" (urlConcat "/adminUser/index" "sorter" .sorter "keywords" .keywords)}}
				{{template "admin/user/page.html" .}}
			</div>
		</div>
	</footer>
</section>
	
{{template "admin/footer.html" .}}

<script>
$(function() {
	$(".send-email").click(function() {
		openSendEmailDialog($(this).data("email"));
	});
	$(".bulk-email").click(function() {
		var emails = [];
		$(".ck:checked").each(function() {
			emails.push($(this).data("email"));
		});
		if(emails.length == 0) {
			art.alert("No user");
			return;
		}
		openSendEmailDialog(emails.join(","));
	});
	
	// reset password
	$(".reset-pwd").click(function() {
		var id = $(this).data("id");
		openDialog({width: 500,  url: "/adminUser/resetPwd?userId=" + id, title: "Reset Password"});
	});
});
</script>

{{template "admin/end.html" .}}
